import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public  class BinaryTree {
    public static int i = 0;
    static class TreeNode {
        char val;
        TreeNode left;
        TreeNode right;

        TreeNode(char val) {
            this.val = val;
        }
    }
    public static TreeNode createTree(String str) {
        //1. 遍历字符串str
        // for(int i = 0;i < str.length();i++) {
        //     char ch = str.charAt(i);
        // }
        TreeNode root = null;
        if(str.charAt(i) != '#') {
            //2. 根据前序遍历创建二叉树
            root = new TreeNode(str.charAt(i));
            i++;
            root.left = createTree(str);
            root.right = createTree(str);
        }else {
            i++;
        }
        //3.返回根节点
        return root;
    }
    public static  void chengxu(TreeNode root){
        Queue<TreeNode> q = new LinkedList<>();
        if(root==null){
            return;
        }
        q.offer(root);
        while(!q.isEmpty()){
            int size=q.size();
            while(size-->0){
                TreeNode node=q.poll();
                System.out.print(node.val);
                if(node.left!=null) q.offer(node.left);
                if(node.right!=null) q.offer(node.right);
            }
        }
        return;
    }
    public static void inorder(TreeNode root) {
        if(root == null) {
            return ;
        }
        inorder(root.left);

        System.out.print(root.val);

        inorder(root.right);

    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();

            TreeNode root = createTree(str);

            chengxu(root);
        }
    }
}



